import request from '@/utils/request'

export const analyticsApi = {
  // 获取仪表盘数据
  getDashboardData(timeRange = '7d') {
    return request.get('/analytics/dashboard', {
      params: { timeRange }
    })
  },

  // 获取访问统计
  getVisitStats(params = {}) {
    return request.get('/analytics/visits', { params })
  },

  // 获取用户行为分析
  getUserBehavior(userId, params = {}) {
    return request.get(`/analytics/users/${userId}/behavior`, { params })
  },

  // 获取页面访问统计
  getPageStats(params = {}) {
    return request.get('/analytics/pages', { params })
  },

  // 获取实时数据
  getRealTimeData() {
    return request.get('/analytics/realtime')
  },

  // 获取系统性能指标
  getSystemMetrics() {
    return request.get('/analytics/system-metrics')
  },

  // 获取转化漏斗数据
  getFunnelData(funnelId, params = {}) {
    return request.get(`/analytics/funnels/${funnelId}`, { params })
  },

  // 获取留存分析
  getRetentionAnalysis(params = {}) {
    return request.get('/analytics/retention', { params })
  },

  // 获取用户画像数据
  getUserPortrait(params = {}) {
    return request.get('/analytics/user-portrait', { params })
  },

  // 获取热力图数据
  getHeatmapData(pageUrl, params = {}) {
    return request.get('/analytics/heatmap', {
      params: { pageUrl, ...params }
    })
  },

  // 获取事件统计
  getEventStats(eventName, params = {}) {
    return request.get('/analytics/events', {
      params: { eventName, ...params }
    })
  },

  // 创建自定义报表
  createCustomReport(reportConfig) {
    return request.post('/analytics/reports', reportConfig)
  },

  // 获取报表列表
  getReports(params = {}) {
    return request.get('/analytics/reports', { params })
  },

  // 获取报表详情
  getReportById(reportId) {
    return request.get(`/analytics/reports/${reportId}`)
  },

  // 更新报表
  updateReport(reportId, reportConfig) {
    return request.put(`/analytics/reports/${reportId}`, reportConfig)
  },

  // 删除报表
  deleteReport(reportId) {
    return request.delete(`/analytics/reports/${reportId}`)
  },

  // 导出报表
  exportReport(reportId, format = 'excel') {
    return request.get(`/analytics/reports/${reportId}/export`, {
      params: { format },
      responseType: 'blob'
    })
  },

  // 获取数据对比分析
  getComparisonData(metrics, params = {}) {
    return request.get('/analytics/comparison', {
      params: { metrics: metrics.join(','), ...params }
    })
  },

  // 获取趋势分析
  getTrendAnalysis(metric, params = {}) {
    return request.get('/analytics/trends', {
      params: { metric, ...params }
    })
  },

  // 获取异常检测数据
  getAnomalyDetection(params = {}) {
    return request.get('/analytics/anomalies', { params })
  },

  // 获取预测分析
  getPredictionData(metric, params = {}) {
    return request.get('/analytics/predictions', {
      params: { metric, ...params }
    })
  },

  // 创建数据提醒
  createAlert(alertConfig) {
    return request.post('/analytics/alerts', alertConfig)
  },

  // 获取提醒列表
  getAlerts() {
    return request.get('/analytics/alerts')
  },

  // 更新提醒状态
  updateAlertStatus(alertId, status) {
    return request.put(`/analytics/alerts/${alertId}/status`, { status })
  },

  // 删除提醒
  deleteAlert(alertId) {
    return request.delete(`/analytics/alerts/${alertId}`)
  }
}
